package com.telephone.purchase.service.impl;


import com.telephone.purchase.service.LoginUserService;
import com.telephone.purchase.dao.UserRepository;
import com.telephone.purchase.entity.LoginUser;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.transaction.Transactional;

/**
 * Created by unicom on 2019/8/29.
 */
@Transactional
@Service
public class LoginLoginUserServiceImpl implements LoginUserService {

    @Autowired
    private UserRepository UserRepository;


    @Override
    public LoginUser findById(Long id) {
        return UserRepository.findUserById(id);
    }

    @Override
    public LoginUser findUserByEmail(String userEmail) {
        return UserRepository.findByEmail(userEmail);
    }

    @Override
    public LoginUser findUserByPhone(String phoneNumber) {
        return UserRepository.findByPhone(phoneNumber);
    }

    @Override
    public LoginUser save(LoginUser loginUser) {
        return UserRepository.save(loginUser);
    }

    @Override
    public int emailIsExist(String userEmail) {
        return UserRepository.emailCount(userEmail);
    }

    @Override
    public String updatePassword(String userPassword, String phoneNumber) {
        try{
            int num = UserRepository.updatePwd(userPassword,phoneNumber);
            System.out.println("数据库update操作结果：" + num);
            return "200";
        } catch (Exception e){
            e.printStackTrace();
            return "406";
        }

    }

}



